package com.example.houseweb.controller;

import com.example.housebiz.service.AgencyService;
import com.example.housebiz.service.HouseService;
import com.example.housebiz.service.RecommendService;
import com.example.housecommon.constants.CommonConstant;
import com.example.housecommon.model.House;
import com.example.housecommon.model.User;
import com.example.housecommon.page.PageData;
import com.example.housecommon.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author ：Anitaxiaofeng
 * @description：
 * @create 2018-06-02
 **/
@Controller
public class AgencyController {


    @Autowired
    private AgencyService agencyService;


    @Autowired
    private RecommendService recommendService;

    @Autowired
    private HouseService houseService;

    @RequestMapping("/agency/agentList")
    public String agentList(Integer pageSize, Integer pageNum, ModelMap modelMap) {
        if(pageSize == null){
            pageSize = 6;
        }
        PageData<User> ps = agencyService.getAllAgent(PageParams.build(pageSize,pageNum));
        List<House> houses = recommendService.getHotHouse(CommonConstant.RECOM_SIZE);
        modelMap.put("recomHouses",houses);
        modelMap.put("ps",ps);
        return "user/agent/agentList";
    }


    @RequestMapping("/agency/agentDetail")
    public String agentDetail(Long id,ModelMap modelMap) {
        User user = agencyService.getAgentDetail(id);
        List<House> houses = recommendService.getHotHouse(CommonConstant.RECOM_SIZE);
        House query = new House();
        query.setUserId(id);
        query.setBookmarked(false);
        PageData<House> bindHouse = houseService.queryHouse(query,new PageParams(3,1));
        if(bindHouse!=null) {
            modelMap.put("bindHouses",bindHouse.getList());
        }
        modelMap.put("recomHouses",houses);
        modelMap.put("agent",user);
        modelMap.put("agencyName",user.getAgencyName());
        return "user/agent/agentDetail";
    }
}




